package mqtt5;


import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Title: MQTTCLIENTS
 * @Package: cn.mis.util.mqtt5
 * @Description: mqtt5所有客户端
 * @Author: ChenLi
 * @Date: 2023/2/16 17:17
 */
@Component
@Slf4j
public class MQTTCLIENTS {

    public static Map<String, Mqtt5Client> CLIENTSMAP = new HashMap<>();
    @Resource
    private Mqtt5Configs mqtt5Configs;

    public void init(){
        if (mqtt5Configs == null || mqtt5Configs.getList().size() == 0){
            log.error("配置文件读取失败");
            return;
        }
        for (Emqx5Config emqx5Config : mqtt5Configs.getList()){
            String clientName = emqx5Config.getClientName();
            Mqtt5Client mqtt5Client = new Mqtt5Client(emqx5Config);
            CLIENTSMAP.put(clientName, mqtt5Client);
            mqtt5Client.init();
        }
    }
}
